﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RA_WebSite.Models;

namespace RA_WebSite.Controllers
{
    public class AnalisiController : Controller
    {
        private RAContext db = new RAContext();

        //
        // GET: /Analisi/

        public ActionResult Index()
        {
            var analisis = db.Analisis.Include(a => a.GradoDiRuggine).Include(a => a.Provino).Include(a => a.TipoDiRuggine);
            return View(analisis.ToList());
        }

        //
        // GET: /Analisi/Details/5

        public ActionResult Details(int id = 0)
        {
            Analisi analisi = db.Analisis.Find(id);
            if (analisi == null)
            {
                return HttpNotFound();
            }
            return View(analisi);
        }

        //
        // GET: /Analisi/Create

        public ActionResult Create()
        {
            ViewBag.GradoDiRuggine_Id = new SelectList(db.GradoDiRuggines, "Id", "Id");
            ViewBag.Provino_Id = new SelectList(db.Provinoes, "Id", "Coordinate");
            ViewBag.TipoDiRuggine_Id = new SelectList(db.TipoDiRuggines, "Id", "Tipo");
            return View();
        }

        //
        // POST: /Analisi/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(Analisi analisi)
        {
            if (ModelState.IsValid)
            {
                db.Analisis.Add(analisi);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.GradoDiRuggine_Id = new SelectList(db.GradoDiRuggines, "Id", "Id", analisi.GradoDiRuggine_Id);
            ViewBag.Provino_Id = new SelectList(db.Provinoes, "Id", "Coordinate", analisi.Provino_Id);
            ViewBag.TipoDiRuggine_Id = new SelectList(db.TipoDiRuggines, "Id", "Tipo", analisi.TipoDiRuggine_Id);
            return View(analisi);
        }

        //
        // GET: /Analisi/Edit/5

        public ActionResult Edit(int id = 0)
        {
            Analisi analisi = db.Analisis.Find(id);
            if (analisi == null)
            {
                return HttpNotFound();
            }
            ViewBag.GradoDiRuggine_Id = new SelectList(db.GradoDiRuggines, "Id", "Id", analisi.GradoDiRuggine_Id);
            ViewBag.Provino_Id = new SelectList(db.Provinoes, "Id", "Coordinate", analisi.Provino_Id);
            ViewBag.TipoDiRuggine_Id = new SelectList(db.TipoDiRuggines, "Id", "Tipo", analisi.TipoDiRuggine_Id);
            return View(analisi);
        }

        //
        // POST: /Analisi/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(Analisi analisi)
        {
            if (ModelState.IsValid)
            {
                db.Entry(analisi).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.GradoDiRuggine_Id = new SelectList(db.GradoDiRuggines, "Id", "Id", analisi.GradoDiRuggine_Id);
            ViewBag.Provino_Id = new SelectList(db.Provinoes, "Id", "Coordinate", analisi.Provino_Id);
            ViewBag.TipoDiRuggine_Id = new SelectList(db.TipoDiRuggines, "Id", "Tipo", analisi.TipoDiRuggine_Id);
            return View(analisi);
        }

        //
        // GET: /Analisi/Delete/5

        public ActionResult Delete(int id = 0)
        {
            Analisi analisi = db.Analisis.Find(id);
            if (analisi == null)
            {
                return HttpNotFound();
            }
            return View(analisi);
        }

        //
        // POST: /Analisi/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            Analisi analisi = db.Analisis.Find(id);
            db.Analisis.Remove(analisi);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}